const express = require('express');
const db = require('../mongodb/db');
const fs=require('fs')
const config = require('../mongodb/config')
var router = express.Router();

db(() => {

})


router.get('/pic', function (req, res, next) {
    let imgList = []
    let choseList = []
    while (imgList.length < 3) {
        let num = Math.floor(Math.random() * 42 + 1)
        if (choseList.includes(num)) continue
        choseList.push(num)
        const data={
            id:num,
            src: `http://${config.IP}:${config.hPort}/public/pic/pic${num}.avif`
        }
        imgList.push(data)
    }
    res.json({
        code:'000',
        msg:'获取图片成功',
        picList:imgList
    })
});

router.get('/picOne', function (req, res, next) {

        let num = Math.floor(Math.random() * 42 + 1)
        const data = {
            id: num,
            src: `http://${config.IP}:${config.hPort}/public/pic/pic${num}.avif`
        }
    
    res.json({
        code: '000',
        msg: '获取图片成功',
        data:data
    })
});
module.exports = router;